package com.mathdroid.exceptionhandling;

/**
 * Caught exceptions should be given to this handler. This handler contains
 * <b>one</b> ErrorFrame. Chains of exceptions are shown in only one frame. 
 */
public final class ExceptionHandler {

	/**
	 * The static ErrorFrame.
	 */
	private static ErrorFrame f = null;
	
	/**
	 * Hide the default constructor.
	 */
	private ExceptionHandler() { }
	
	/**
	 * Show an exception in the ErrorFrame.
	 * @param cause The cause of the exception. Can be null.
	 * @param e The exception.
	 */
	public static void report(final String cause, final Exception e) {
		e.printStackTrace();
		
		if (f == null) {
			f = new ErrorFrame();
		}
		
		f.appendError(cause, e);
		f.setVisible(true);
	}
}
